package test00;

import entity.Student;

import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * @Author lzp
 * @Date 2024-03-26
 */
public class test05 {
    public static void main(String[] args) throws Exception {

        //Scanner scanner1 = new Scanner(System.in);
        //System.out.println("请输入年份");
        //int year = scanner1.nextInt();

        //获取类的 class 对象
        Class<Scanner> clazz = Scanner.class;

        //实例化对象  -  getConstructor获取构造函数   -  newInstance 通过反射动态创建一个类的实例
        Scanner scanner = clazz.getConstructor(InputStream.class).newInstance(System.in);

        System.out.println("请输入年份");
        //获取方法 - 公开
        Method studyMethod = clazz.getMethod("nextInt");

        //调用方法 .invoke
        int year = (int)studyMethod.invoke(scanner);
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){
            System.out.println("是闰年");
        }
        else {
            System.out.println("是平年");
        }


    }
}
